<%@page import="java.util.ArrayList"%>
<%@page import="study.top.mydb.items.Category2Item"%>
<%@page import="study.top.mydb.Category2"%>
<%@page import="study.top.mydb.items.Category1Item"%>
<%@page import="study.top.mydb.Category1"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ page trimDirectiveWhitespaces="true" %>
<%@ include file="dbcon.jsp" %>
<%
	int seq = web.getInt("seq");

	//카테고리1 목록에 대한 ArrayList 받아오기
	Category1 dept1 = new Category1();
	ArrayList<Category1Item> Ca1_list = dept1.selectCategory1List();
	
	// 카테고리2 수정
	Category2 ca2 = new Category2();
	Category2Item item = ca2.show(seq);
	
	//접속종료
	db.disconnect();
	
	if(item == null){
		out.print("<script type='text/javascript'>alert('데이터 조회에 실패했습니다. 잠시후 다시 시도해 주세요.'); history.back(); </script>");
		return;
	}
%>
<!DOCTYPE html>
<html lang="ko">
	<head>
		<meta charset="UTF-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no"/>
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
		<title>부서관리 - 추가</title>

		<!-- 모바일 웹 페이지 설정 -->
		<link rel="shortcut icon" href="assets/ico/favicon.png" />
		<link rel="apple-touch-icon-precomposed" href="assets/ico/apple-touch-icon-57-precomposed.png" />
		<link rel="apple-touch-icon-precomposed" sizes="72x72" href="assets/ico/apple-touch-icon-72-precomposed.png" />
		<link rel="apple-touch-icon-precomposed" sizes="114x114" href="assets/ico/apple-touch-icon-114-precomposed.png" />
		<link rel="apple-touch-icon-precomposed" sizes="144x144" href="assets/ico/apple-touch-icon-144-precomposed.png" />

		<!-- bootstrap -->
		<link rel="stylesheet" type="text/css" href="assets/css/bootstrap.min.css" />
		<!-- 나눔고딕 웹 폰트 적용 -->
		<link rel="stylesheet" type="text/css" href="assets/css/nanumfont.css" />
		<!-- 반응형 웹을 지원하지 않을 경우 -->
		<!-- <link rel="stylesheet" href="assets/css/non-responsive.css" /> -->

		<!-- IE8 이하 버전 지원 -->
		<!--[if lt IE 9]>
		<script type="text/javascript" src="assets/js/html5shiv.js"></script>
		<script type="text/javascript" src="assets/js/respond.min.js"></script>
		<![endif]-->

		<!-- IE10 반응형 웹 버그 보완 -->
		<!--[if gt IE 9]>
		<link rel="stylesheet" type="text/css" href="assets/css/ie10.css" />
		<script type="text/javascript" src="assets/js/ie10.js"></script>
		<![endif]-->
	</head>

	<body>
		<div class="container">
        	<div class="page-header">
        		<h1>상위메뉴 수정</h1>
        	</div>        	
        	
        	<form id="frmDepartmentEdit" class="form-horizontal" role="form"
        	method="post" action="aCategory2EditOk.jsp">
        	
        	<input type="hidden" name="seq" value="<%=seq%>"/>
        		<fieldset>
        			
        			<div class="form-group">
						<label for="seq" class="col-md-2 control-label">상위분류 선택</label>
						<div class="col-md-10">
							<select id="ca1seq" name="ca1seq" class="form-control">
								<%
									if (Ca1_list != null) {
										for (int i=0; i<Ca1_list.size(); i++) {
											Category1Item c1_item = Ca1_list.get(i);
									// 디비의 seq 와 드롭다운 리스트 seq 와 일치할때 selected = true 옵션 부여
								%>
								<option value="<%=c1_item.getSeq()%>"<%if(c1_item.getSeq() == item.getC1_seq()){%>selected<%}%>><%=c1_item.getSeq()%>. <%=c1_item.getC1_name()%></option>
								<%
										}
									}
								%>
							</select>
						</div>
					</div>
        			
        			<!--  입력양식 -->
        			<div class="form-group">
        				<label for="dname" class="col-md-2 control-label">하위분류 수정</label>
        				<div class="col-md-10">
        					<input type="text" class="form-control"
        					id = "name" placeholder="하위분류 이름를 입력하세요."
        					name="name" value="<%=item.getC2_name()%>">
        				</div>
        			</div>
        			<!--//입력양식  -->
        			<div class="form-group">
        				<div class="col-md-offset-2 col-md-10">
        					<div class="row">
        						<div class="col-md-6">
        							<button type="submit" class="btn btn-primary
        							 btn-block">수정하기</button>
        						</div>
        						<div class="col-md-6">
        							<a href="javascript:history.back()" class="btn btn-info btn-block">뒤로가기</a>
        						</div>
        					</div>
        				</div>
        			</div>
        			
        		</fieldset>
        	</form>        	
        </div>
		
		<!-- Javascript -->
		<script src="assets/js/jquery.js"></script>
		<script src="assets/js/bootstrap.min.js"></script>
		<!-- 형식검사 클랫 ㅡ참조 -->
		<script src="assets/js/string.js"></script>
		<!-- 구현 부분 -->
		<script type="text/javascript">
			// jquery main()
			$(function(){
				//id속성이 frmStudentAdd인 대상에 대한 전송 이벤트
				$("#frmDepartmentEdit").submit(function(){

					
					var name = $("input[name='name']").val();
					// 학과명 입력여부 검사
					if(!name.isValue()){
						alert("카테고리 명을 입력하세요.");
						$("input[dname='dname']").focus();
						return false;
					}					
				});
			});
		</script>
	</body>
</html>